﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;

namespace HospitalMedicineTraceability
{
    public partial class frmGoodsCodeCheck : DevComponents.DotNetBar.OfficeForm
    {
        public Dictionary<string, string> m_dictInfo = new Dictionary<string, string>(); // 回传信息(指定对码时用)
        public string m_strWhere = "";  //
        public frmGoodsCodeCheck()
        {
            InitializeComponent();
        }
        #region  1.自定义方法
        /// <summary>
        /// 初始化
        /// </summary>
        private void _init() {
            // 控件赋初始值
            txtCode0.Text = m_dictInfo["Code"];
            txtName0.Text = m_dictInfo["Name"];
            txtPackageSpec0.Text = m_dictInfo["PackageSpec"];
            txtManufacturer0.Text = m_dictInfo["Manufacturer"];
            txtUnit0.Text = m_dictInfo["Unit"];            
        }
        private void _save() {
            if (txtCode.Text.Equals("")) {
                CommFun._messageBoxShow("请先确定His商品！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // 清除原有数据
            string strSql = "exec P_DealGoodsCodeCheck 'Save','{0},{1},{2},{3}'";
            strSql = string.Format(strSql, m_dictInfo["Code"], txtCode.Text, AppInfo.m_UserInfo.m_strCode, AppInfo.m_UserInfo.m_strName);
            DataTable dt = null;
            dt = AppInfo._openSql_DataTable(strSql);

            if (dt!=null && dt.Rows.Count > 0 && dt.Rows[0]["IsOK"].ToString() == "1")
            {
                CommFun._messageBoxShow("His商品对码成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult = DialogResult.OK;
            }
            else {
                CommFun._messageBoxShow(string.Format("His商品对码失败！{0}", dt.Rows[0]["Message"].ToString()), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        #endregion

        #region 2.系统事件方法
        private void frmEnterpriseCodeCheck_Load(object sender, EventArgs e)
        {
            _init();
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            _save();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        private void btnQuery_Click(object sender, EventArgs e)
        {
            //扫码入库(需先进行扫码配企确定)
            frmQuerySelect frm = new frmQuerySelect();
            frm.m_nKind = 10;
            frm.m_strInfo = m_dictInfo["Name"];
            frm.m_strWhere = " ";
            if (frm.ShowDialog() == DialogResult.OK)
            {
                txtCode.Text = frm.m_dictSelected["Code"];
                txtName.Text = frm.m_dictSelected["Name"];
                txtPackageSpec.Text = frm.m_dictSelected["PackageSpec"];
                txtManufacturer.Text = frm.m_dictSelected["Manufacturer"];
                txtUnit.Text = frm.m_dictSelected["Unit"];
            }
        }
    }
}
